﻿using UnityEngine;
using System.Collections;

public class AfterImageTransparent : MonoBehaviour {

    float tempTime;

    Material material;

    void Start()
    {
        tempTime = 0.0f;
        material = GetComponent<Renderer>().material;
        material.shader = Shader.Find("Transparent/Diffuse");
        material.color = new Color(
            material.color.r,
            material.color.g,
            material.color.b,
            material.color.a - tempTime / 50);
    }
    void Update()
    {
        if (tempTime < 1)
        {
            tempTime = tempTime + Time.deltaTime;
        }
        else
        {
            Destroy(transform.gameObject);
        }
        if (material.color.a <= 1)
        {
            material.color = new Color(
            material.color.r,
            material.color.g,
            material.color.b,
            material.color.a - tempTime / 50);
        }
    }
}
